Lab 3 The assignment consists of several parts. 1. Split the SIM4 source file into seven different C files called header.h, main.c, fetch.c, execute.c, skipop.c onereg.c tworeg.c, and utility.c (containing panic(), trace(), and readcode()). Test your code by compiling the code and executing a test program. (Hint "gcc header.h main.c fetch.c execute.c skipop.c onereg.c tworeg.c") 2. Create a shell script called "simscript" to compile your seven C files to create an executable called SIM. The file "simscript" look something like this. should #!/bin/sh # remember "chmod 700 simscript" before you run simscript gcc c header.h main.c # produces main.o gcc c header.h fetch.c # produces fetch.o gcc c header.h execute.c # products execute.o gcc c header.h skipop.c # products skipop.o gcc c header.h onereg.c # products onereg.o gcc c header.h teoreg.c # products tworeg.o gcc c header.h utility.c # products utility.o gcc o sim5 main.o fetch.o execute.o skipop.o onereg.o tworeg.o utility.o # produces sim5 3. Create a makefile to replace the shell script. (With the make file, you only have to recompile the C files that have been modified.) 4. Modify the C code for sim4.c to create sim5.c by adding the following four instructions. The operations codes are at the end of the SIM reference card. (NOTE Your printed version of the SIM reference card lists the call op code as "950s" when it should be "960s". a. A push instruction, push %rn, that pushes register n on the stack. Because %r9 is the instruction pointer and %r8 is the link register, use %r7 as the stack pointer. For example, the instruction "push %r5" should perform the equivalent of the following in a single instruction: dec %r7 mov %r5,(%r7) b. A pop instruction, pop %rn, that pops a value from the stack into register n. For example, the instruction "pop %r5" should perform the equivalent of the following: mov (%r7),%r5 inc %r7 c. A call instruction, call %rn, that calls a function whose address is contained in register n. For example, the instruction "call %r0" should perform (almost) the equivalent of the following: push %r9 same as dec %r7 mov %r0,%r9 mov %r9,(%r7) mov %r0,%r9 Note that you can't use the two instructions above to call a function because the value saved on the stack is the address of the "mov %r0,%r9" instruction rather than the instruction following the move. However, when you combine the two instructions into one "call" instruction, the correct value of %r9 is saved on the stack. d. A return instruction, ret, that returns from a called function to the calling function. For example, the instruction "ret", should perfrom the equivlanet of the following: pop %r9 You don't need to create new instruction. Just use the "pop %r9" instruction and call it "ret" in assembly language. 5. Test your code by executing all of the "sim5" programs in the SIM5 section of the SIM manual. Hand in: a. A listing of your C code with all changes highlighted. b. A listing of your makefile. c. The results of running the SIM5 programs. d. Your SIM5 program documentation (see my SIM1 thorugh SIM4 program socumentation).